package com.itheima.test.atom.atomsynchronized;

public class MyAtom implements Runnable{//每个线程送100个冰淇淋,一个100个线程
    private int count = 0;
    private Object lock = new Object();
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            synchronized (lock) {//用锁可解决count++非原子性的问题
                count++;
                System.out.println("已送出"+count+"个冰淇淋");
            }
        }
    }
}
